This invention relates to color rendering in computer graphics systems and, more particularly, to methods and apparatus for performing fog blending on a per pixel basis.
Computer graphics systems commonly are used for displaying graphical representations of objects on a two dimensional display screen. Current computer graphics systems can provide highly detailed representations and are used in a variety of applications.
In typical computer graphics systems, an object to be represented on a display screen is broken down into a plurality of graphics primitives. Primitives are basic components of a graphics picture such as points, lines, vectors and polygons (i.e., triangles). Typically, a hardware/software scheme is implemented to render (draw) on a two-dimensional display screen, the graphics primitives that comprise a view of one or more objects.
A host computer commonly provides primitive data that represents the primitives of a three-dimensional object to be rendered. When the primitive is a triangle, for example, the host computer may define the triangle in terms of the X, Y, Z coordinates of its vertices, as well as the red, green, blue (R, G, B) color values of each vertex. Rendering hardware interpolates the primitive data to compute the display screen pixels that comprise each primitive, and the R, G, B color values for each pixel.
The basic components of a typical computer graphics system include a geometry accelerator, a rasterizer and a frame buffer. The system also may include other hardware such as texture mapping hardware (described below). The geometry accelerator receives, from the host computer, vertex coordinate and color data for primitives that comprise an object. The geometry accelerator typically performs transformations on the vertex coordinate data (i.e., to screen space coordinates), decomposes quadrilaterals into triangles, and may perform other functions such as lighting, clipping and producing plane equation calculations for each primitive. The output from the geometry accelerator, referred to as rendering data, is used by the rasterizer (and optional texture mapping hardware) to compute final screen space coordinates and R, G, B color values for each pixel comprising the primitives. The final data is stored in the frame buffer for display on a display screen. Some graphics systems are pipelined such that various operations (such as transformations, interpolation, etc.) are performed simultaneously by different components on different object primitives.
More sophisticated systems offer texture mapping as an option so that objects can be displayed with improved surface detail. Texture mapping is a method that involves mapping a source image, referred to as a texture, onto a surface of a three-dimensional object, and thereafter mapping the textured three-dimensional object to the two-dimensional graphics display screen to display the resulting image. Texture mapping involves applying one or more texture elements (texels) of a texture to each picture element (pixel) of the displayed portion of the object to which the texture is being mapped. Texture mapping hardware subsystems typically include a local memory that stores texture data associated with the object being rendered.
Depth cueing is another technique for producing a more realistic display. In depth cueing, an object""s color is gradually blended into the background color (also known as the depth cue color), based on the distance from the viewer to the object. This distance is usually approximated by the depth, or Z value, of the object. Depth cueing may be used for simulating the atmospheric attenuation of light intensity. Thus, as objects get farther from the viewer, they appear dimmer. Any color can be used as the depth cue color, but black is used most often.
Fog blending is still another technique for producing a more realistic display. In fog blending, an object""s color is gradually blended into an arbitrary color (the fog color), using a fog blending factor f, which is primarily based on the distance from the eye point of the viewer of the object. This distance is usually approximated by the distance, or Z value, of the object between the eye and the object in eye coordinates, wherein the eye coordinates are defined as being negative when Z is in front of the eye.
It is a general object of the present invention to provide an improved fog blending for color rendering in a computer graphics system.
It is an object of the present invention to provide fast and accurate exponential and exponential squared fog blending.
This and other objects are obtained generally by providing a computer graphics system having an apparatus for fog blending colors. The apparatus includes a rendering parameter calculation unit that in response to data of a primitive that is to be displayed, determines a cooked exponent value and a color value for at least one pixel of the primitive. In addition, the apparatus includes a fog unit responsive to the cooked exponent value for each pixel of the primitive, that determines a fog blending factor for each pixel of the primitive, wherein the fog blending factor is one of an exponential fog blending factor and an exponential-squared fog blending factor. Further, the apparatus includes a fog blending unit responsive to the color value and the fog blending factor for each pixel of the primitive and also responsive to a fog color value, that blends the fog color value with the color value for each pixel of the primitive according to the fog blending factor for each pixel of the primitive and that outputs a fogged color value for each pixel of the primitive.
In one embodiment of the computer graphics system, the apparatus includes a first interpolator, responsive to the cooked exponent value and the color value for at least one pixel of the primitive, that determines the cooked exponent value and the color value along an edge of the primitive and that provides, at an output, the cooked exponent value and the color value for each pixel of the edge of the primitive.
In another embodiment of the computer graphics system, the apparatus includes a second interpolator, responsive to the cooked exponent value and the color value for each pixel of the edge of the primitive, that determines the cooked exponent value and the color value along a span of the primitive and that provides, at an output, the cooked exponent value and the color value for each pixel of the span of the primitive.
In a further embodiment of the computer graphics system, the fog unit includes a lookup table having a first column of entries that correspond to a first part of a 2xe2x88x92fraction portion of the fog blending factor for a plurality of possible bits of the cooked exponent value, and a second column of entries that correspond to a delta between two consecutive entries in the first column of entries. The fog unit also includes a multiplier that is responsive to the delta value provided by the lookup table and to additional bits of the cooked exponent value, that multiplies the delta value with the additional bits of cooked exponent value and that provides an interpolated value of a second part of the 2xe2x88x92fraction portion of the fog blending factor at an output of the multiplier. The fog unit further includes a subtractor that is responsive to the interpolated value of the second part of the 2xe2x88x92fraction portion of the fog blending factor and to one of the entries of the first column of entries of the lookup table that subtracts the interpolated value of the second part of the 2xe2x88x92fraction portion of the fog blending factor from the first part of the 2xe2x88x92fraction portion of the fog blending factor to provide at an output a value of the 2xe2x88x92fraction portion of the fog blending factor. Still further, the fog unit comprises a barrel shifter that shifts to the right the value of the 2xe2x88x92fraction portion of the fog blending factor by an integer value so as to provide multiplication of the 2xe2x88x92fraction portion of the fog blending factor with a 2xe2x88x92fraction portion of the fog blending factor, and that provides at an output the fog blending factor.
In accordance with another aspect of the present invention, in a computer graphics system comprising a geometry accelerator and a rasterizer that together generate a graphics image on a video display screen, a method for fog blending colors in the graphics system is provided. The method comprises the steps of determining a cooked exponent value and a color value for at least one pixel of a primitive to be displayed on the video display screen in response to data of the primitive. In addition, the method comprises determining a fog blending factor for each pixel of the primitive in response to the cooked exponent value for each pixel of the primitive, wherein the fog blending factor is one of an exponential fog blending factor and an exponential-squared fog blending factor. Still further, the color value for each pixel of the primitive is blended with a fog color value according to the fog blending factor for each pixel of the primitive so as to provide a fogged color value for each pixel of the primitive.
In one embodiment of the method of the present invention, the method further comprises the step of interpolating the color value and the cooked exponent value along an edge of the primitive in response to the color value and the cooked exponent value for at least one pixel of the primitive, to provide the color value and the cooked exponent value for each pixel of the edge of the primitive.
In another embodiment of the method of the present invention, the method further comprises the step of interpolating the cooked exponent value and the color value along a span of the primitive, in response to the cooked exponent value and the color value for each pixel of the edge of the primitive, to provide the cooked exponent value and the color value for each pixel of the span of the primitive.
In a further embodiment of the method of the present invention, the step of determining the fog blending factor includes determining, with a lookup table, a first part of a 2xe2x88x92fraction portion of the fog blending factor. In addition, the step of determining the fog blending factor further includes linearly interpolating a second part of the 2xe2x88x92fraction portion of the fog blending factor. Further, the step of determining the fog blending factor includes subtracting the second part of the 2xe2x88x92fraction portion of the fog blending factor from the first part of the 2xe2x88x92fraction portion of the fog blending factor to determine the 2xe2x88x92fraction portion of the fog blending factor. Still further, the step of determining the fog blending factor includes multiplying the 2xe2x88x92fraction portion of the fog blending factor with a 2xe2x88x92fraction portion of the fog blending factor by shifting, to the right, the 2xe2x88x92fraction portion of the fog blending factor by the integer value.
The features and advantages of the present invention will be more readily understood and apparent from the following detailed description of the invention, which should be read in conjunction with the accompanying drawings and from the claims which are appended to the end of the detailed description.